#!/sbin/openrc-run

description="Start a Jenkins slave"

name="java"
command="/usr/bin/java"
command_args="-Xmx{{ server_ram|default('128m') }} \
  -jar /home/{{ server_user }}/slave.jar -secret {{ secret }} \
  -jnlpUrl {{ jenkins_url }}/computer/{{ inventory_hostname }}/slave-agent.jnlp \
  -slaveLog /home/{{ server_user }}/slave.log"


depend() {
        need net localmount
        after firewall
}

start() {
        export PATH="/usr/lib/ccache/bin:$PATH"
        export JOBS={{ jobs_env }}
        export HOME=/home/{{ server_user }}
        export NODE_TEST_DIR=${HOME}/tmp
        export NODE_COMMON_PIPE=/home/{{ server_user }}/test.pipe

        ebegin "Starting jenkins slave"
        start-stop-daemon --start --background --make-pidfile \
                --user {{ server_user }} --group {{ server_user }} \
                --pidfile=/run/jenkins.pid --exec ${command} \
                -- ${command_args}
}

stop() {
        ebegin "Stopping jenkins slave"
        start-stop-daemon --stop --quiet --pidfile=/run/jenkins.pid
}
